package com.viethp.mt.common;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.viethp.mt.common.CommonHelper;
import com.viethp.mt.common.GlobalVariables;
import com.viethp.mt.objects.Position;

public class MyLocationListener implements LocationListener {
	private Context context;

	public MyLocationListener(Context context) {
		this.context = context;
	}

	public void onLocationChanged(Location loc) {
		loc.getLatitude();
		loc.getLongitude();
		GlobalVariables.lat = loc.getLatitude();
		GlobalVariables.lon = loc.getLongitude();

		Position pos = new Position();
		pos.setLon(String.valueOf(GlobalVariables.lon));
		pos.setLat(String.valueOf(GlobalVariables.lat));
		CommonHelper.setPosition(pos, context);

		String Text = "My current location is: " + "Latitud = "
				+ GlobalVariables.lat + "Longitud = " + GlobalVariables.lon;
		// Toast.makeText(context, Text, Toast.LENGTH_SHORT).show();
		Log.d("LocationListener", Text);
		// setMap(GlobalVariables.lat,GlobalVariables.lon);
	}

	public void onProviderDisabled(String provider) {
		// Toast.makeText(context, "Gps Disabled", Toast.LENGTH_SHORT).show();
		CommonHelper.showWarning(context,
				"Gps Disabled. Please enable to detect your location!");
	}

	public void onProviderEnabled(String provider) {
		Toast.makeText(context, "Gps Enabled", Toast.LENGTH_SHORT).show();
	}

	public void onStatusChanged(String provider, int status, Bundle extras) {
	}
}
